#include "pch.h"
#include "seCircleProgress.h"

sf::Image seCircleProgress::mImage;

seCircleProgress::seCircleProgress()
{

}

void seCircleProgress::Load()
{
	if(!mImage.LoadFromFile("data/circle-load.png"))
		printf("Blad przy wczytywaniu obraszka circle-load.png\n");
}

void seCircleProgress::Unload()
{

}

void seCircleProgress::Init()
{
	mCurrentPercentOfTheCircle = 0.0f;
	mMaxPercentOfTheCircle = 100.0f;
	mProgressDuration = 8.0f;
	mPosition = sf::Vector2f(0.0f, 0.0f);
	mState = true;
}

void seCircleProgress::Step()
{
	if(mState) mCurrentPercentOfTheCircle += 100 * ONE_FRAME_DURATION/mProgressDuration;
	else
	{
		mCurrentPercentOfTheCircle -= 400 * ONE_FRAME_DURATION/mProgressDuration;
		if(mCurrentPercentOfTheCircle < 0.0f) mCurrentPercentOfTheCircle = 0;
	}
	if(mCurrentPercentOfTheCircle > 100.0f) mState = false;
}

void seCircleProgress::Draw()
{
	sf::Sprite sprite(mImage);
	sprite.SetCenter((float)mImage.GetWidth() / 2.0f, (float)mImage.GetHeight());
	sprite.SetPosition(mPosition);
	for(int i = 0; i < (int)mCurrentPercentOfTheCircle*3.6f; ++i)
	{
		sprite.Rotate(1.0f);
		app.Draw(sprite);
	}
}

float seCircleProgress::GetPercentage()
{
	return mCurrentPercentOfTheCircle;
}

bool seCircleProgress::GetState()
{
	return mState;
}

void seCircleProgress::SetState(bool val)
{
	mState = val;
}

void seCircleProgress::SetPosition(sf::Vector2f vec2f)
{
	mPosition = vec2f;
}

void seCircleProgress::SetProgressDuration(float val)
{
	mProgressDuration = val;
}